<template>
  <div class="home-new">
    <HomePanel title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
      <template #right>
        <XtxMore />
      </template>
      <div ref="target" style="position: relative; height: 406px">
        <Transition name="fade">
          <!-- 面板内容 -->
          <ul v-if="goods.length" class="goods-list" ref="pannel">
            <li v-for="item in goods" :key="item.id">
              <RouterLink to="/">
                <img v-lazy="item.picture" alt="" />
                <p class="name ellipsis">{{ item.name }}</p>
                <p class="price">&yen;{{ item.price }}</p>
              </RouterLink>
            </li>
          </ul>
          <HomeSkeleton v-else bg="#f0f9f4" />
        </Transition>
      </div>
    </HomePanel>
  </div>
</template>

<script>
import HomePanel from "./home-panel.vue";
import { findNew } from "@/api/home.js";
// import { ref } from "vue";
// *引入骨架组件
import HomeSkeleton from "./home-skeleton.vue";
// *引入数据懒加载函数
import { useLazyData } from "@/hooks";

export default {
  name: "HomeNew",
  props: {},
  components: {
    HomePanel,
    HomeSkeleton,
  },
  setup() {
    // const goods = ref([]);
    // findNew().then((data) => {
    //   goods.value = data.result;
    // });
    // *使用数据懒加载函数 1.target是监听的目标dom对象 2.useLazyData()是传入的api函数 在useLazyData内部调用
    const { result, target } = useLazyData(findNew);
    return { goods: result, target };
  },
};
</script>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f1f6fd;
    border-radius: 15px 0;
    overflow: hidden;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
